/*******************************************************************************
03_02: Make Table X2: Effect of source country characteristics on non-market work 
	when controling for gender composition of children and the interaction with GGI

Replication code for "Culture and gender allocation of tasks: source country 
	characteristics and the division of non-market work among US immigrants" in
	Review of Economics of the Household

Authors: Francine Blau, Lawrence Kahn, Matthew Comey, Amanda Eng, Pamela 
	Meyerhofer, and Alexander Willen
	
Date: 10/16/2020

*******************************************************************************/


/*******************************************************************************

I. Preliminaries

*******************************************************************************/

***A. Erase existing output if necessary
cap erase "$tables/Table_X2_Panel_A.xls"
cap erase "$tables/Table_X2_Panel_A.txt"
cap erase "$tables/Table_X2_Panel_B.xls"
cap erase "$tables/Table_X2_Panel_B.txt"
cap erase "$tables/Table_X2_Panel_C.xls"
cap erase "$tables/Table_X2_Panel_C.txt"
cap erase "$tables/Table_X2_Panel_D.xls"
cap erase "$tables/Table_X2_Panel_D.txt"


***B. Set control variables
local fe i.day i.month i.year i.state

*First Generation Control Variables
local im_controls age age2 hsdi scol cold RACE2 RACE3 RACE4 RACE5 yrsusa1 yrsusa2 cohort70_79 cohort80_89 cohort90_99 cohort00_09 cohort10_17

local im_part_controls part_age part_age2 part_hsdi part_scol part_cold part_RACE2 part_RACE3 part_RACE4 part_RACE5 part_immig part_secondgen part_yrsusa1 part_yrsusa2 part_cohort70_79 part_cohort80_89 part_cohort90_99 part_cohort00_09 part_cohort10_17

*Secong Generation Control Variables
local sg_controls age age2 hsdi scol cold RACE2 RACE3 RACE4 RACE5

local sg_part_controls part_age part_age2 part_hsdi part_scol part_cold part_RACE2 part_RACE3 part_RACE4 part_RACE5 part_immig part_secondgen part_yrsusa1 part_yrsusa2 part_cohort70_79 part_cohort80_89 part_cohort90_99 part_cohort00_09 part_cohort10_17

/*******************************************************************************

II. Run Regressions

*******************************************************************************/

local maintit "Table X2: Effect of source country characteristics on non-market work when controling for gender composition of children and GGI interaction"

**Loop through table panels
foreach panel in A B C D {
	
	*Set sample restrictions and labels
	preserve
	
	if "`panel'" == "A" {
	    di "*****Regressing Immigrant Women with Children*****"
		
		drop if hh_numownkids== 0
		keep if youngc<18 
		keep if female == 1 & immig==1
		
		local tabtit "`maintit', Panel A. Immigrant Women with Children"
		
		local main_controls `im_controls' `im_part_controls' `fe'
		local source_vars GGI GDP_000 fertility
		local main_int GGIxyoung_children GGIxmiddle_children GGIxold_children
		local sex_int  GGIxyoung_girls GGIxmiddle_girls GGIxold_girls GGIxyoung_boys GGIxmiddle_boys GGIxold_boys
		local cluster cluster(bpl)
		}
	else if "`panel'" == "B" {
	    di "*****Regressing Immigrant Men with Children*****"
		
		drop if hh_numownkids== 0
		keep if youngc<18 
		keep if female == 0 & immig==1
		
		local tabtit "`maintit', Panel B. Immigrant Men with Children"
		
		local main_controls `im_controls' `im_part_controls' `fe'
		local source_vars GGI GDP_000 fertility
		local main_int GGIxyoung_children GGIxmiddle_children GGIxold_children
		local sex_int  GGIxyoung_girls GGIxmiddle_girls GGIxold_girls GGIxyoung_boys GGIxmiddle_boys GGIxold_boys
		local cluster cluster(bpl)
		}
	else if "`panel'" == "C" {
	    di "*****Regressing 2nd-Gen Immigrant Women with Children*****"
		
		drop if hh_numownkids== 0
		keep if youngc<18 
		keep if female == 1 & secondgen==1
		
		local tabtit "`maintit', Panel C. 2nd-Gen Immigrant Women with Children"
		
		local main_controls `sg_controls' `sg_part_controls' `fe'
		local source_vars parent_GGI parent_GDP_000 parent_fertility
		local main_int parent_GGIxyoung_children parent_GGIxmiddle_children parent_GGIxold_children
		local sex_int  parent_GGIxyoung_girls parent_GGIxmiddle_girls parent_GGIxold_girls parent_GGIxyoung_boys parent_GGIxmiddle_boys parent_GGIxold_boys
		local cluster cluster(parent_bpl)
		}
	else if "`panel'" == "D" {
	    di "*****Regressing 2nd-Gen Immigrant Men with Children*****"
		
		drop if hh_numownkids== 0
		keep if youngc<18 
		keep if female == 0 & secondgen==1
		
		local tabtit "`maintit', Panel D. 2nd-Gen Immigrant Men with Children"
		
		local main_controls `sg_controls' `sg_part_controls' `fe'
		local source_vars parent_GGI parent_GDP_000 parent_fertility
		local main_int parent_GGIxyoung_children parent_GGIxmiddle_children parent_GGIxold_children
		local sex_int  parent_GGIxyoung_girls parent_GGIxmiddle_girls parent_GGIxold_girls parent_GGIxyoung_boys parent_GGIxmiddle_boys parent_GGIxold_boys
		local cluster cluster(parent_bpl)
		}


	**Loop through non-market work variables
	foreach var in $nmw $hwork $ccare { 
		
		if "`var'" == "$nmw" {
			local coltit "Total Non-Market Work"
			}
		else if "`var'" == "$hwork" {
			local coltit "Housework"
			}
		else if "`var'" == "$ccare" {
			local coltit "Childcare"
			}
			
		*Children interations
		reg `var' `source_vars' young_children middle_children old_children `main_int' `main_controls' [aw=newwt], robust `cluster'
		quietly summ `var' [aw=newwt] if e(sample)==1   
		outreg2 using "$tables/Table_X2_Panel_`panel'.xls", keep(`source_vars' young_children middle_children old_children `main_int') append ctitle(`coltit') addstat(Mean, r(mean))  label title("`tabtit'") nocons
		
		if "`panel'" == "A" | "`panel'" == "B" {
			display "Joint Test of Interactions"
			test GGIxyoung_children GGIxmiddle_children GGIxold_children
			}
		else if "`panel'" == "C" | "`panel'" == "D" {
			display "Joint Test of Interactions (C1)"
			test parent_GGIxyoung_children parent_GGIxmiddle_children parent_GGIxold_children
			}
			
		*Children interactions split by gender
		reg `var' `source_vars' young_girls middle_girls old_girls young_boys middle_boys old_boys `sex_int' `main_controls' [aw=newwt], robust `cluster'
		quietly summ `var' [aw=newwt] if e(sample)==1   
		outreg2 using "$tables/Table_X2_Panel_`panel'.xls", keep(`source_vars' young_girls middle_girls old_girls young_boys middle_boys old_boys `sex_int') append ctitle(`coltit') addstat(Mean, r(mean))  label title("`tabtit'") nocons
		
		if "`panel'" == "A" | "`panel'" == "B" {
			display "Joint Test of Interactions"
			test GGIxyoung_girls GGIxmiddle_girls GGIxold_girls GGIxyoung_boys GGIxmiddle_boys GGIxold_boys
			
			display "Test of GGI*young Equality"
			test GGIxyoung_girls = GGIxyoung_boys
			display "Test of GGI*middle Equality"
			test GGIxmiddle_girls = GGIxmiddle_boys
			display "Test of GGI*old Equality"
			test GGIxold_girls = GGIxold_boys
			
			display "Accumulation Test"
			qui test GGIxyoung_girls = GGIxyoung_boys
			qui test GGIxmiddle_girls = GGIxmiddle_boys, acc
			test GGIxold_girls = GGIxold_boys, acc
			}
		else if "`panel'" == "C" | "`panel'" == "D" {
			display "Joint Test of Interactions"
			test parent_GGIxyoung_girls parent_GGIxmiddle_girls parent_GGIxold_girls parent_GGIxyoung_boys parent_GGIxmiddle_boys parent_GGIxold_boys
				
			display "Test of GGI*young Equality"
			test parent_GGIxyoung_girls = parent_GGIxyoung_boys
			display "Test of GGI*middle Equality"
			test parent_GGIxmiddle_girls = parent_GGIxmiddle_boys
			display "Test of GGI*old Equality"
			test parent_GGIxold_girls = parent_GGIxold_boys
			
			display "Accumulation Test"
			qui test parent_GGIxyoung_girls = parent_GGIxyoung_boys
			qui test parent_GGIxmiddle_girls = parent_GGIxmiddle_boys, acc
			test parent_GGIxold_girls = parent_GGIxold_boys, acc
			}
		
		}
		
	restore
	
	}
	
	
***Erase text files
cap erase "$tables/Table_X2_Panel_A.txt"
cap erase "$tables/Table_X2_Panel_B.txt"
cap erase "$tables/Table_X2_Panel_C.txt"
cap erase "$tables/Table_X2_Panel_D.txt"
